<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
		<form name="form_search" id="form_search" action="{:U('index')}" method="post">
			<input type="hidden" name="is_warn" value="{$search.is_warn}">
		    <table width="100%" cellspacing="0" class="search-form">
		        <tbody>
		            <tr>
			            <td>
				            <div class="explain-col">							
								<select name="cate_code" style="width:250px;" class="chosen_search">
									<option value="">全部分类列表</option>
	                				<volist name="cateTree" id="val_1">
								    	<option value="{$val_1.code}"  <if condition="$val_1['code'] eq $search['cate_code']">selected</if>>{$val_1.code}-{$val_1.title}</option>
										<volist name="val_1['children']" id="val_2">
											<option value="{$val_2.code}"  <if condition="$val_2['code'] eq $search['cate_code']">selected</if>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$val_2.code}{$val_2.title}</option>								
										</volist>
	                				</volist>
								</select>
								<select name="is_show" style="width:150px;" class="chosen_search">
									<option value="">状态：全部</option>
									<option value="1" <if condition="$search['is_show'] eq '1'">selected</if>>已上架</option>
	                				<option value="0" <if condition="$search['is_show'] eq '0'">selected</if>>未上架</option>
								</select>
								<select name="stock_qty" style="width:150px;" class="chosen_search">
									<option value="">库存：全部</option>
									<option value="0" <if condition="$search['stock_qty'] eq '0'">selected</if>>无库存</option>
									<option value="1" <if condition="$search['stock_qty'] eq '1'">selected</if>>有库存</option>
	                				<option value="10" <if condition="$search['stock_qty'] eq '10'">selected</if>>大于10件</option>
	                				<option value="50" <if condition="$search['stock_qty'] eq '50'">selected</if>>大于50件</option>
	                				<option value="100" <if condition="$search['stock_qty'] eq '100'">selected</if>>大于100件</option>
								</select>
								<input type="text" name="name" value="{$search.name}" placeholder="商品名称">
								<input type="text" name="barcode" value="{$search.barcode}" placeholder="条形码">
								<input type="button"  name="form_search_btn_search"  value="查询" onclick="document.forms['form_search'].submit()"/>	
				        	</div>
			            </td>
		            </tr>
		        </tbody>
		    </table>
	    </form>
	    <form  name="form_list" id="form_list" action="{:U('index')}" method="post">
		    <div class="table-list">		
			    <table width="100%" cellspacing="0">
			        <thead>
			            <tr>
			            	<th width="40" align="center">图片</th>  
			            	<th width="60" align="left">条形码</th>               
			                <th width="120" align="left">商品名称</th>
			                <th width="80" align="left">规格/单位</th>
			                <th width="60" align="left">实际价格</th>
			      			<th width="40" align="left">热门</th>
			      			<th width="40" align="left">推荐</th>
			      			<th width="40" align="left">上架</th>
			                <th width="60" align="left">报警量</th>
			                <th width="50" align="left">库存量</th>
			                <th width="60" align="left">增加存量</th>
			      			<th align="left">操作(更新日期)</th>
			            </tr>
			        </thead>
			    	<tbody>
						<volist name="list" id='val'>
				        <tr>
				        	<td align="center"><img src="{$val.prod_id|m_prod_pic}?{$Think.now} "  id="pic_{$val.prod_id}" width=45  height=30></td>
				            <td align="left">{$val.barcode}</td>
				            <td align="left"><span>{$val.name}</span></td>
				            <td align="left">{$val.spec|m_prod_spec=$val['spec_qty'],$val['spec_unit']}</td>
				            <td align="left">{$val.price_real}</td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_hot')" id="is_hot_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_hot}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_recommend')" id="is_recommend_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_recommend}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_show')" id="is_show_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_show}.png" /></td>
				            <td align="left">				            
				            	<input type="text" class="input-text-c input-text" value="{$val.stock_warn_qty}" size="4" name="stock_warn_qty[]" id="stock_warn_qty{$val.prod_id}" onblur="doUpdStockWarnQty('{:U('doUpdStockWarnQty')}','{$val.prod_id}')"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
							</td>
				            <td align="left" id="stock_qty{$val.prod_id}">{$val.stock_qty}</td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="" size="4" name="add_stock_qty[]" id="add_stock_qty{$val.prod_id}"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
							</td>
				            <td align="left" class="btn">
				            	<a class="link_btn" href="#" onclick="doAddStockQty('{:U('doAddStockQty')}','{$val.prod_id}');return false;" >添加库存</a>
				            	<a class="link_btn" href="#" onclick="openDialogLog('{:U('Product/ProductLogManage/showList')}','{$val.prod_id}','stock')" >历史记录</a>
				            </td>
				        </tr>
				        </volist>
			    	</tbody>
			    </table>
	
			    <div class="btn">
					<div id="pages">{$page}</div>
			    </div>
	    	</div>
	    </form>
	</div>
	<div id="dialog_content" title="弹出框"></div>
<script type="text/javascript">

$(function(){
	//打开窗口
	$( "#dialog_content" ).dialog({
		autoOpen: false,
		width:600,
		height:400
	});
})
//显示变更历史窗口
function openDialogLog(action_url,prod_id,type){
	$.post(
		action_url, 
		{"prod_id":prod_id,"type":type}, 
		function(htmldata){
			$("#dialog_content").dialog("option","title","库存变更记录");
			$("#dialog_content").html(htmldata).dialog("open");
		},
		"html"
	);
	return false;
}
function doAddStockQty(action_url,prod_id){
	var qty = $('#add_stock_qty'+prod_id).val();
	if(!checkRegex(qty,regexEnum.intege)||qty==0){
		alert("请输入正确的数字");
		return false;
	}else{
		$.get(action_url, { prod_id: prod_id, add_stock_qty: qty }, function(jsondata){
			if(jsondata['error']==0){
				alert('添加成功，现在的库存是：'+jsondata['stock_qty']);
				$('#add_stock_qty'+prod_id).val('');
				$('#stock_qty'+prod_id).html(jsondata['stock_qty']);
				$('#stock_qty'+prod_id).css('color','blue');
				return false;
			}else{
				if(jsondata['message']==''){
					alert('数据未发生变化');
				}else{
					alert(jsondata['message']);
				}
				return false;
			}
		},'json'); 
	}
	return false;
}
function doUpdStockWarnQty(action_url,prod_id){
	var qty = $('#stock_warn_qty'+prod_id).val();
	if(!checkRegex(qty,regexEnum.intege)||qty==0){
		alert("请输入正确的数字");
		return false;
	}else{
		$.get(action_url, { prod_id: prod_id, add_stock_qty: qty }, function(jsondata){
			if(jsondata['error']==0){
				$('#stock_warn_qty'+prod_id).css('color','blue');
				return false;
			}else{
				if(jsondata['message']==''){
					alert('数据未发生变化');
				}else{
					alert(jsondata['message']);
				}
				return false;
			}
		},'json'); 
	}
}

</script>
</block>